package com.kadron.color;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.kadron.common.KConst;
import com.kadron.dao.KCommonDAO;
import com.kadron.entity.Color;
import com.kadron.manager.KMessageManager;

@AutoCreate
@Name("kColorManager")
@Scope(ScopeType.PAGE)
public class KColorManager extends KMessageManager implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4184026689307942094L;

	private static final Log log = LogFactory.getLog(KColorManager.class);
	
	private Color color; 
	
	@In
	private KCommonDAO commonDAO;
	
	@Create
	public void init() {
		Long colorId = (Long) Component.getInstance("colorId");
		if (colorId == null) {
			colorId = new Long(0);
		}
		if (colorId > 0) {
			color = (Color) commonDAO.find(colorId, Color.class);
		} else {
			color = new Color();
		}
	}
	
	public String save() {
		if (color == null) {
			bad(KConst.BAD_THING);
			return null;
		}
		if (log.isDebugEnabled()) {
			log.debug("Save Color colorId="+color.getId());
		}
		commonDAO.update(color);
		good();
		return "color";
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}
}
